#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"

#define KEY_VALUE       0xf0
#define INVALID_VALUE   0x00

int main(int argc, char *argv[])
{
    int ret = 0;
    int fd = 0;
    char *filename = NULL;
    unsigned char data;
    if(argc != 2)
    {
        printf("error args!\n");
        return -1;
    }
    
    filename = argv[1];
    fd = open(filename, O_RDWR);
    if(fd < 0)
    {
        printf("file %s open failed!\n", filename);
        return -1;
    }
    while(1)
    {
        ret=read(fd, &data, sizeof(data));
        if (ret < 0) {  /* 数据读取错误或者无效 */
			
		} else {		/* 数据读取正确 */
			if (data)	/* 读取到数据 */
				printf("key value = %#X\r\n", data);
		}
        
    }
    close(fd);
    return ret;
}